package com.qf.shopping.controll.activityControll;

import com.qf.shopping.pojo.activity.ActivityChannel;
import com.qf.shopping.service.activityService.IAcitvityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Mawentao
 * @Date: 2019/5/9 0009 17:03
 * @Description:
 */
@Controller
@RequestMapping("/activitychannel")
public class ActivityChannelControll {

    @Autowired
    private IAcitvityService acitvityService = null;

    /**
     *获取列表
     * @param model
     * @return
     */
    @GetMapping("activitychannel")
    public String getList(Model model){
        List<ActivityChannel> activityChannels = acitvityService.findActivityChannel(null,0);
        model.addAttribute("activityChannel",activityChannels);

        return "/activity/activityChannel/list";
    }

    /**
     * 搜索
     * @am model
     * @param name
     * @return
     */
    @PostMapping("getactivitychannel")
    public String getActivityChannel(Model model,String name){
        List<ActivityChannel> activityChannels = acitvityService.findActivityChannelLike(name);
        model.addAttribute("activityChannel",activityChannels);
        return "/activity/activityChannel/list";
    }

    /**
     * 添加
     * @param activityChannel
     * @return
     */
    @PostMapping("addactivitychannel")
    public String addActivityChannel(ActivityChannel activityChannel){
        acitvityService.insertActivityChannel(activityChannel);
        return "redirect:/activitychannel/activitychannel";
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("deleteactivitychannel/{id}")
    public String deleteActivityChannel(@PathVariable("id")Long id){
        acitvityService.deleteActivityChannel(id);
        return "redirect:/activitychannel/activitychannel";
    }

    /**
     * 跳转到更新页面
     * @param model
     * @param id
     * @return
     */
    @GetMapping("/updateactivitychannel/{id}")
    public String updateActivityChannel(Model model,@PathVariable("id")Long id){
        ActivityChannel activityChannel = acitvityService.getActivityChannel(id);
        model.addAttribute("activityChannel",activityChannel);
        return "/activity/activityChannel/update";
    }

    /**
     * 编辑活动类型
     * @param activityCategory
     * @return
     */
    @PostMapping("updateactivitychannel")
    public String updateActivityChannel(ActivityChannel activityCategory){
        acitvityService.updateActivityChannel(activityCategory);
        return "redirect:/activitychannel/activitychannel";
    }
}
